#include"BlockQueue.hpp"
#include"Task.hpp"
void *Consumer(void *arg)
{
 auto bq=(BlockQueue<Task>*) arg;
 while(1)
 {
  sleep(1);
  Task t;
  bq->Pop(t);
  t.Run();
//  cout<<"consumer:"<<date<<endl;//消费数据
//   printf("Consumer %d\n",date);
 }
}

void *Producter(void* arg)
{
 auto bq=(BlockQueue<Task>*) arg;
 while(1)
 {
  const char* arr="+-*/";

  int x=rand()%100+1;
  int y=rand()%50;
  char op= arr[rand()%4];
  Task t(x,y,op);
  bq->Push(t);
  cout<<"Producter task done"<<endl;
 // cout<<"Producter:"<<date<<endl;
 //  printf("Producter %d\n",date);
  // sleep(1);
 }

}
int main()
{
  srand((unsigned int)time(nullptr));
  BlockQueue<Task> *bq=new BlockQueue<Task>();
  
  pthread_t c,p;
  pthread_create(&c,nullptr,Consumer,bq);
  pthread_create(&p,nullptr,Producter,bq);



  pthread_join(c,nullptr);
  pthread_join(p,nullptr);

  return 0;
}
